from datetime import datetime

from django.db import models
from django.contrib.auth import get_user_model

from goods.models import Goods

User = get_user_model()

class UserFav(models.Model):

    user = models.ForeignKey(User, on_delete=models.DO_NOTHING,)
    goods = models.ForeignKey(Goods,on_delete=models.DO_NOTHING,)

    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间", help_text="添加时间")


    class Meta:
        verbose_name = ("UserFav")
        verbose_name_plural = ("UserFavs")

    def __str__(self):
        return self.user.name

    def get_absolute_url(self):
        return reverse("UserFav_detail", kwargs={"pk": self.pk})

class UserLeavingMsgs(models.Model):

    user = models.ForeignKey(User,on_delete=models.DO_NOTHING,)
    msg_type = models.CharField(max_length=100)
    subJect = models.CharField(max_length=100)
    message = models.CharField(max_length=100)
    file = models.FileField(upload_to='brands/')

    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间", help_text="添加时间")


    class Meta:
        verbose_name = ("UserLeavingMsgs")
        verbose_name_plural = ("UserLeavingMsgss")

    def __str__(self):
        return self.subJect

    def get_absolute_url(self):
        return reverse("UserLeavingMsgs_detail", kwargs={"pk": self.pk})


class UserAddress(models.Model):

    user = models.ForeignKey(User,on_delete=models.DO_NOTHING,)
    address = models.CharField(max_length=100)
    signer_name = models.CharField(max_length=100)
    signer_mobile = models.CharField(max_length=100)

    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间", help_text="添加时间")


    class Meta:
        verbose_name = "UserAddress"
        verbose_name_plural = "UserAddress"

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse("UserAddress_detail", kwargs={"pk": self.pk})
